home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / GFSOUNIT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  6.0 KB  |  207 lines

  1. #include <stdlib.h>
  2. #include "gfsounit.h"
  3.  
  4. Gfso::Gfso(int Ba, int Fa, ColorPak &Cp)
  5. // Initializes the three components of a Gfso: the interior, frame,
  6. // and overall objects. Gfso also supports a new type of frame
  7. // style: windows with CloseBoxes. The dimensions of the close box
  8. // is hard-coded, but looks good in most cases. 
  9. : Fso(Ba, Fa, Cp)
  10. {
  11.   Overall = new Grso;
  12.   Frame   = new Grso;
  13.   Interior = new Grso;
  14.   SaveBuff = NULL;  SwapBuff = NULL;
  15.   SaveSize = 0;
  16.   if (IsCloseable()) {
  17.      // Create a close box and place it within a 16 pixel header
  18.      // at the top of the window 
  19.      CloseBox = new Grso;
  20.      CloseBox->SetSize(11, 11);   // Hard coded 
  21.      HeaderHt = 16; // Frame header height is hard coded 
  22.   }
  23.   else CloseBox = NULL;
  24. }
  25.  
  26. Gfso::~Gfso(void)
  27. // Frees the swap buffers and the four nested Grso objects 
  28. {
  29.   if (IsSwappable()) {
  30.      delete[SaveSize] SaveBuff;
  31.      delete[SaveSize] SwapBuff;
  32.   }
  33.   if (IsCloseable()) delete CloseBox;
  34.   delete Frame;
  35.   delete Interior;
  36.   delete Overall;
  37. }
  38.  
  39. void Gfso::SetSize(int W, int H)
  40. // Sets the size of the three components of a Gfso object and 
  41. // its CloseBox if it has one. The size (W,H) is interpreted 
  42. // to be the interior size. Memory for the swap buffers is also 
  43. // allocated if the object is swappable, but only if the first 
  44. // time, or if the new size is bigger than the old. 
  45. {
  46.   unsigned OldSaveSize;
  47.  
  48.   Interior->SetSize(W, H);
  49.   if (IsCloseable())
  50.      Frame->SetSize(W+Bwd*2, H+HeaderHt+Bwd*2);
  51.      else Frame->SetSize(W+Bwd*2, H+Bwd*2);
  52.   Overall->SetSize(Frame->Wd, Frame->Ht);
  53.   if (IsSwappable()) {
  54.      OldSaveSize = SaveSize;
  55.      SaveSize = imagesize(Frame->Xul,Frame->Yul,Frame->Xlr,Frame->Ylr);
  56.      if (SaveSize > OldSaveSize) { // Allocate 
  57.         if (SaveBuff != NULL) {    // Re-allocate 
  58.            delete[OldSaveSize] SaveBuff;
  59.            delete[OldSaveSize] SwapBuff;
  60.         }
  61.         SaveBuff = new char[SaveSize];
  62.         SwapBuff = new char[SaveSize];
  63.      }
  64.   }
  65. }
  66.  
  67. void Gfso::SetLocn(int Xl, int Yl)
  68. // Sets the upper-left location of the three Grsos and the 
  69. // CloseBox if this object has one 
  70. {
  71.   Frame->SetLocn(Xl, Yl);
  72.   if (IsCloseable()) {
  73.     Interior->SetLocn(Xl+Bwd, Yl+Bwd+HeaderHt);
  74.     CloseBox->SetLocn(Xl+Bwd+5, Yl+Bwd+2);
  75.   }
  76.   else Interior->SetLocn(Xl+Bwd, Yl+Bwd);
  77.   Overall->SetLocn(Xl, Yl);
  78. }
  79.  
  80. void Gfso::DrawFrame(char Ba, char Attr)
  81. // Draws this object's frame and its CloseBox if it has one 
  82. {
  83.   int I;
  84.  
  85.   if (Bwd > 0) {
  86.      if (Ba == 0) Ba = (Bstyle << 4) | Bwd;
  87.      if (Attr == 0) Attr = Colors.Bc;
  88.      Frame->Box(0, 0, Frame->Wd, Frame->Ht, Ba, Attr);
  89.      if (IsCloseable()) {
  90.         // This object has a CloseBox. Display it now 
  91.         Mouse.Hide();
  92.         for (I = 0; I < HeaderHt; I++) {
  93.           if ((I % 2) == 0) 
  94.          setcolor(0);
  95.          else setcolor(BackGround(Colors.Wc));
  96.       moveto(Frame->Xul+Bwd, Frame->Yul+Bwd+I);
  97.       lineto(Frame->Xlr-Bwd, Frame->Yul+Bwd+I);
  98.     }
  99.     CloseBox->Fill(0, 0, CloseBox->Wd, CloseBox->Ht, ' ', Colors.Wc);
  100.     CloseBox->Box(0, 0, CloseBox->Wd, CloseBox->Ht, Relief+1, Attr);
  101.     Mouse.Show();
  102.      }
  103.   }
  104. }
  105.  
  106. int Gfso::OnCloseButton(int X, int Y)
  107. // Returns True if the coordinate is within the object's CloseBox. 
  108. // This function returns False if the object does not have a CloseBox. 
  109. {
  110.   return (IsCloseable() && CloseBox->Contains(X, Y));
  111. }
  112.  
  113. void Gfso::Clear(char Ch, char Attr)
  114. // Clears the interior of this object using the colors in Attr. If
  115. // Attr is zero, then the window color field of this object is used. 
  116. {
  117.     if (Attr > 0) Colors.Wc = Attr;
  118.     Interior->Fill(0, 0, Interior->Wd, Interior->Ht, Ch, Colors.Wc);
  119. }
  120.  
  121. void Gfso::GetImage(Rect *)
  122. // Gets image from frame buffer and stores it in the save buffer if
  123. // the object is swappable. The clipping rectangle for the
  124. // shadows is not currently used. 
  125. {
  126.   Mouse.Hide();
  127.   if (IsSwappable()) 
  128.      ::getimage(Frame->Xul, Frame->Yul, Frame->Xlr, Frame->Ylr, SaveBuff);
  129.   Mouse.Show();
  130. }
  131.  
  132. void Gfso::PutImage(Rect *)
  133. // Puts save buffer image onto Frame buffer if the object
  134. // is swappable. The clipping rectangle for the shadows
  135. // is not currently used. 
  136. {
  137.   Mouse.Hide();
  138.   if (IsSwappable())
  139.      ::putimage(Frame->Xul, Frame->Yul, SaveBuff, COPY_PUT);
  140.   Mouse.Show();
  141. }
  142.  
  143. void Gfso::Swap(Rect *, XfrDirn)
  144. // Swaps the image on the screen.
  145. // Note: the parameters aren't used here. 
  146. {
  147.   char *Tmp;
  148.  
  149.   if (IsSwappable()) {
  150.      Mouse.Hide();
  151.      ::getimage(Frame->Xul, Frame->Yul, Frame->Xlr, Frame->Ylr, SwapBuff);
  152.      ::putimage(Frame->Xul, Frame->Yul, SaveBuff, COPY_PUT);
  153.      Mouse.Show();
  154.      // Just swap pointers between SwapBuff and SaveBuff 
  155.      Tmp = SaveBuff; SaveBuff = SwapBuff;  SwapBuff = Tmp;
  156.   }
  157. }
  158.  
  159. int Gfso::TextWidth(char *Str)
  160. // Returns the pixel width of the string. 
  161. // Note the typecast, so that the right width is returned.
  162. {
  163.   return ((Grso *)Interior)->TextWidth(Str);
  164. }
  165.  
  166. int Gfso::TextHeight(int N)
  167. // Returns the pixel height of N rows of text 
  168. // Note the typecast, so that the right height is returned.
  169. {
  170.   return ((Grso *)Interior)->TextHeight(N);
  171. }
  172.  
  173. // ---------------- Graphics Skeleton Methods ------------------- 
  174.  
  175. Gskel::Gskel(ColorPak &Cp)
  176. // Initializes a graphics skeleton object so that it has a
  177. // single pixel border and is swappable
  178. : Fso(0x11, Swappable, Cp) 
  179. {
  180.   Overall = new Grso;
  181.   Frame   = new Grso;
  182.   Interior = new Grso;
  183. }
  184.  
  185. void Gskel::DrawFrame(char Ba, char Attr)
  186. // Draws the frame of a skeleton object using dashed, 
  187. // exclusive-OR lines 
  188.   setlinestyle(DASHED_LINE,0,NORM_WIDTH);
  189.   setwritemode(XOR_PUT);
  190.   if (Ba == 0) Ba = (Bstyle << 4) + Bwd;
  191.   if (Attr == 0) Attr = Colors.Bc;
  192.   Box(0, 0, Frame->Wd, Frame->Ht, Ba, Attr);
  193.   setwritemode(COPY_PUT);
  194.   setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  195. }
  196.  
  197. void Gskel::Swap(Rect *, XfrDirn)
  198. // Swapping graphics skeleton objects is simply accomplished by
  199. // calling DrawFrame again. This works because DrawFrame uses
  200. // exclusive-OR lines. Note: this version doesn't use the parameters. 
  201. {
  202.   DrawFrame(0,0);
  203. }
  204.  
  205.  
  206.